Passed
Push — develop ( 5e54f0...8faf31 )
by Endre
05:14
created

Application   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 35
rs 10
c 0
b 0
f 0
ccs 11
cts 11
cp 1
wmc 7

5 Functions

Rating   Name   Duplication   Size   Complexity  
A render 0 6 2
A attachToModuleState 0 3 1
A attachToMenuOpenState 0 3 1
A attachToLanguage 0 3 1
A attachToContainerNode 0 4 2
1
import React from 'react';
2
import ListenerAdapter from '../Observer/ListenerAdapter';
3
import {IObserverAdapter} from '../Observer/Observer';
4
import {IPageData} from '../Router/Router';
5
import ApplicationView, {IAdapter as IViewAdapter} from './View/Application';
6
import Model from './View/Application/Model';
7
import {IPresenter as IApplicationPresenter}  from './View/Application/Presenter';
8
9
export interface IModulePageData extends IPageData {
10
  module: string
11
}
12
13
export interface IAdapter extends IViewAdapter {
14
  onPageChanged(newValue: IPageData): void;
15
}
16
17
export default class Application {
18
  private readonly adapter: IAdapter;
19
  private readonly presenter: IApplicationPresenter;
20
  private view: ApplicationView | undefined;
21
  private readonly renderCallback: OmitThisParameter<() => void>;
22
23
  constructor(adapter: IAdapter, presenter:IApplicationPresenter) {
24 5
    this.presenter = presenter;
25 5
    this.adapter = adapter;
26 5
    this.renderCallback = this.render.bind(this);
27
  }
28
29
  attachToLanguage(adapter:ListenerAdapter<string>) {
30 5
    adapter.addListener(this.renderCallback);
31
  }
32
33
  attachToModuleState(adapter:ListenerAdapter<typeof React.Component | null>) {
34 5
    adapter.addListener(this.renderCallback);
35
  }
36
37
  attachToMenuOpenState(adapter: IObserverAdapter<boolean>) {
38 5
    adapter.onChange = this.renderCallback;
39
  }
40
41
  attachToContainerNode(containerNode: Element | DocumentFragment | null) {
42 4
    if (containerNode == null) return;
43 4
    this.view = new ApplicationView(containerNode, this.adapter);
44
  }
45
46
  render() {
47 6
    if (this.view == undefined) return;
48
49 4
    const model: Model = this.presenter.present();
50 4
    this.view.render(model);
51
  }
52
}
53